<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="css/message.css">
    <script src="js/jquery.min.js"></script>
</head>

<body>
    <div>
        <h1>留言板</h1>
        <ul></ul>
        <textarea placeholder="请编辑您的留言"></textarea>
        <button class="sub">发布</button>
    </div>
</body>
<!-- javascript写的 -->
<!-- <script>
    var sub = document.querySelector('.sub');
    var ul = document.querySelector('ul');
    var textarea = document.querySelector('textarea');


    sub.addEventListener('click',function () {
        if (textarea.value=='') {
            return
        }
        var li = document.createElement('li');
        li.innerHTML = textarea.value + '<button class = "remove">删除</button>'
        ul.prepend(li);
        textarea.value = ''; 
        var remove = document.querySelector('.remove')
         remove.addEventListener('click', function() {
         li.remove();
    });
    })
</script> -->
<!-- jquery写的 -->
<script>
    $('.sub').click(function(){
        if ($('textarea').val() == '') {
            return
        }
        $('ul').prepend('<li>' + $('textarea').val() + '<button class = "remove">删除</button></li>')
        $('textarea').val('')
        $('.remove').click(function(){
            $(this).closest('li').remove()
        })
    }) 
</script>

</html>